﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 点节点
/// </summary>
public class Node : IHeapItem<Node>{

	public bool walkable;
	public bool moveable;
	public Vector2 worldPosition;
	public int gridX;
	public int gridY;
	/// <summary>
	/// 移动权值
	/// </summary>
	public int movementPenalty;
	/// <summary>
	/// 到起始节点的cost
	/// </summary>
	public int gCost;
	/// <summary>
	/// 到目标节点的cost
	/// </summary>
	public int hCost;

	public Node parent;
	int heapIndex;

	/// <summary>
	/// gCost + hCost
	/// </summary>
	public int fCost {
		get {
			return gCost + hCost;
		}
	}

	public Node(bool _walkable, bool moveable, Vector2 _worldPos, int _gridX, int _gridY, int _penalty) {
		walkable = _walkable;
		worldPosition = _worldPos;
		gridX = _gridX;
		gridY = _gridY;
		movementPenalty = _penalty;
	}

	public int HeapIndex {
		get {
			return heapIndex;
		}
		set {
			heapIndex = value;
		}
	}

	public int CompareTo(Node other) {
		int compare = fCost.CompareTo(other.fCost);
		if(compare == 0) {
			compare = hCost.CompareTo(other.hCost);
		}
		return -compare;
	}
}
